<?php

/*
 * Встроенные средства отладки
 */

namespace T4;

class Debug {
	
	const SESSION_KEY = 't4:debug';
	
	protected static $sqlLog  = array();
	protected static $callLog = array();
	
	protected static $timer = array();
	
	public static function timerBegin() {
		self::$timer[] = microtime(true);
	}
	
	public static function timerEnd() {
		$delta = microtime(true) - array_pop(self::$timer);
		return $delta;
	}
	
	public static function logSQL($query, $time=0) {
		self::$sqlLog[] = array(
			'query' => $query,
			'time' => $time
		);
	}
	
	public static function logCall($application, $controller, $action, $time=0) {
		self::$callLog[] = array(
			'application' => $application,
			'controller' => $controller,
			'action' => $action,
			'time' => $time
		);
	}
	
	public static function getLog() {
		return array(
			'sql'  => self::$sqlLog,
			'call' => self::$callLog
		);
	}
	
}